package org.rich.charlesmurphy.ui;


import java.awt.Dimension;

import org.ddevil.data.set.DataSet;
import org.rich.charlesmurphy.core.CMIds;
import org.rich.charlesmurphy.model.Request;
import org.rich.charlesmurphy.ui.renderers.FileTypeColorRenderer;
import org.rich.charlesmurphy.ui.renderers.StatusRenderer;
import org.rich.charlesmurphy.ui.renderers.UrlRenderer;
import org.windowkit.toolkit.widget.table.RecordTablePane;

/**
 *
 * @author Rich O'Connell
 */
public class ViewByRequest extends AbstractTableView {
	private static final long serialVersionUID = 6671017278509237076L;

	private static String[] COLUMN_IDS = {
		CMIds.REMOTE_HOST,
		CMIds.START_TIME,
		CMIds.METHOD,
		CMIds.PATH,
		CMIds.STATUS,
		CMIds.RESPONSE_BODY_SIZE,
		CMIds.QUERY,
		CMIds.ELAPSED_TIME
	};

	public ViewByRequest(String title) {
		super(title);
	}

	@Override
	public Dimension requestDimesions() {
		return new Dimension(600, 320);
	}

	@Override
	protected String[] getColumnIds() {
		return COLUMN_IDS;
	}


	@Override
	protected void initComponents() {
		super.initComponents();
		RecordTablePane rtp = getTable();
		rtp.setColumnVisible(CMIds.QUERY, false); // TODO maybe append to path
		rtp.setColumnVisible(CMIds.ELAPSED_TIME, false); // not usually present
		FileTypeColorRenderer colorRenderer = new FileTypeColorRenderer();
		rtp.setColumnCellRenderer(CMIds.PATH, new UrlRenderer(colorRenderer));
		rtp.setColumnCellRenderer(CMIds.METHOD, colorRenderer);
		rtp.setColumnCellRenderer(CMIds.STATUS, new StatusRenderer());

		// TODO bleh...
		rtp.setColumnWidths(new int[]{ 90, 90, 35, 200, 35, 80, 10, 10});

	}
	public void setModel(DataSet<Request> model) {
		setTitle(getTitle() + "[Total: " + model.size() + "]");
		getTable().setData(model);
	}
	
}
